package homeworks.cjt2009.homework1.tsetso.solution;

import java.util.Collection;

public class Guest implements Comparable<Guest>{
	// --- Fields --------------------------------------------------------------
	private String name = null;
	private String email = null;

	// --- Constructors --------------------------------------------------------

	public Guest(String name, String email) {
		this.name = name;
		this.email = email;
	}

	// --- Getters & Setters ---------------------------------------------------
	public String getName() {
		return name;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	// --- Methods -------------------------------------------------------------
	@Override
	public String toString() {
		String resultString = "Guest: name= " + name + ", email= " + email;
		return resultString;
	}

	@Override
	public boolean equals(Object obj) {
		if (!(obj instanceof Guest)) {
			throw new IllegalArgumentException("Incorrect input object "
					+ "in equals method of Guest class.");
		}
		return this.getName() == ((Guest) obj).getName();
	}

	@Override
	public int hashCode() {
		return getName().hashCode();
	}
	
	@Override
	public int compareTo(Guest guest){
		return getName().compareTo(guest.getName());
	}
	
	public static String toStringGuests(Collection<Guest> guests) {
		if (guests == null) {
			throw new IllegalArgumentException("Null-argument passed to "
					+ "toStringGuests() method in class Guest");
		}

		StringBuilder resultString = new StringBuilder();
		for (Guest guest : guests) {
			resultString.append("\t").append(guest).append("\n");
		}
		return resultString.toString();
	}
}
